package com.xaicode.template.druid.web;

import com.alibaba.druid.support.json.JSONUtils;
import com.xaicode.template.druid.entity.User;
import com.xaicode.template.druid.repo.CmdMapper;
import com.xaicode.template.druid.repo.UserRepository;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author xiachangjian <xiachangjian@sataero.cn>
 * @date 2023/2/20
 * @since v2.0.1
 */
@RestController
@ResponseBody
public class UserController {

    @Resource
    private UserRepository userRepository;

    @Resource
    private CmdMapper cmdMapper;

    @GetMapping("t1")
    public String t1() {
//        List<User> all = userRepository.findAll();
//        return JSONUtils.toJSONString(all);

        userRepository.alterCol();
        return "1";
    }

    @GetMapping("t2")
    public String t2() {
        String sql = "alter table sys_user alter column name varchar(34);";
        Object exec = cmdMapper.exec(sql);
        return JSONUtils.toJSONString(exec);
    }

}
